package com.ly.mpayment.persist.service.businesstype;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.ly.mpayment.persist.entity.BusinessType;
import com.ly.mpayment.persist.hibernate.Page;
import com.ly.mpayment.persist.service.AbstractService;

@Service
public class BusinessTypeServiceImpl extends AbstractService<BusinessType, Serializable> implements IBusinessTypeService {

	@Override
	public boolean addBusinesstype(BusinessType business) {
		if(business != null){
			this.saveOrUpdate(business);
			return true;
		}
		return false;
	}

	@Override
	public BusinessType findById(String id) {
		return this.findUnique("select b from BusinessType b where b.status = 1 and b.busuuid = ?", id);
	}

	@Override
	public Page<BusinessType> findPageBusiness(Map<String, Object> parameters, int start, int pageSize) {
		return this.findPageByNamed("select b from BusinessType b where 1 = 1  #[and b.busname like :busname ]#  #[and b.busCode like :busCode ]# order by b.status desc", parameters, start, pageSize);
	}

	@Override
	public boolean updateBusiness(BusinessType business) {
		if(business != null){
			this.saveOrUpdate(business);
			return true;
		}
		return false;
	}

	@Override
	public List<BusinessType> findAllBus() {
		return this.find("select b from BusinessType b where b.status = 1 order by b.busname");
	}

	@Override
	public BusinessType findByName(String busname) {
		return this.findUnique("select b from BusinessType b where b.busname = ?", busname);
	}

	@Override
	public BusinessType findByCode(String buscode) {
		return this.findUnique("select b from BusinessType b where b.busCode = ?", buscode);
	}

}
